<?php
$messages = $this->items;
$timeFormat = \Managers\Utils::DATETIME_FORMAT;
?>
<div class="content-box">

    <div class="content-box-header">
        <h3>Delivery messages</h3>
        <ul class="content-box-tabs">
            <li><a class="default-tab" href="#tab1">Table</a></li>
        </ul>
        <div class="clear"></div>
    </div>
    <div class="content-box-content">
        <div class="tab-content default-tab" id="tab1">
            <a href="/admin/messages/add" class="btn">Add message</a>
            <div class="row">
                <div class="span8">
                    <table class="table table-striped">
                        <thead>
                        <tr>
                            <th>#</th>
                            <th>Title</th>
                            <th>Delivered</th>
                            <th>Start time</th>
                            <th></th>
                        </tr>
                        </thead>
                        <tbody>
                        <?php foreach ($messages as $key => $message): ?>
                        <tr>
                            <td><?php echo  $key + 1 ?></td>
                            <td><?php echo $this->escape($message['title']); ?></td>
                            <td>
                                <input type="checkbox" <?php echo $message['isDelivered'] ? "checked" : false ?> disabled="disabled">
                            </td>
                            <td>
                                <?php if ($message['startTime'] instanceof \DateTime): ?>
                                    <?php echo $message['startTime']->format($timeFormat) ?>
                                <?php else: ?>
                                    No start time.
                                <?php endif; ?>
                            </td>
                            <td>
                                <a href="/admin/messages/now/id/<?php echo $message['id'] ?>" class="btn">
                                    Now
                                </a>
                                <a href="/admin/messages/edit/id/<?php echo $message['id'] ?>" class="btn btn-success">
                                    Edit
                                </a>
                                <a href="/admin/messages/delete/id/<?php echo $message['id'] ?>"
                                   class="btn btn-danger delete">
                                    Delete
                                </a>
                            </td>
                        </tr>
                            <?php endforeach; ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>